-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[nikohomecontrol] Fix things staying offline #12819
Conversation
This is perfectly expected to set a thing status in thing handler initialize() before returning. So the code you removed is correct. |
Prefer several small PRs and you will get a faster feedback. |
I was wrong, it is checked ... but very late in the thing initialization. Maybe the problem. |
|
Setting the thing status to UNKNOWN early in bridge initialization causes the thing initialization to start. And that is faster than the bridge initialization, therefore the things end offline. Removing it corrects it all. |
.../java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java
Outdated
Show resolved
Hide resolved
.../java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlActionHandler.java
Outdated
Show resolved
Hide resolved
@lolodomo - I added a few comments which are now resolved. Please have a final look as you also had some concerns - and merge if everything is okay with you. |
@lolodomo Is there anything left you would want me to look into? I looked again at the sequence of setting the bridge and thing status. There is nothing obvious to simplify it when I look at it. Let me know if you have suggestions. |
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, | ||
"@text/offline.configuration-error.invalid-bridge-handler"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change the thing status here. This is normally already handled by the thing initialization stuff.
If something is not yet ready when handling a command, log something (DEBUG level) if you like and just return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. See also #12331.
} else { | ||
updateStatus(ThingStatus.UNKNOWN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommended practice is to have initialize() setting a valid status (ONLINE / OFFLINE / UNKNOWN) before returning and so before running additional code in a separate thread.
Look at the template: https://github.com/openhab/openhab-core/blob/main/tools/archetype/binding/src/main/resources/archetype-resources/src/main/java/internal/__bindingIdCamelCase__Handler.java#L80
Same remark for everywhere where you removed the set of status to UNKNOWN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize does set the status, and the removed lines make sure it is only set when all of the initialization logic has executed. However, the bridge status can change if communication is lost. I do agree that the UNKNOWN status could not happen, so the last else would not be needed, but I added it for completeness. Should I remove it and replace by some debug log?
The PR title is already a derivation to the recommendation ;) Yes, a valid thing status must be set quickly. If the full initializatoon of the thing handler requires time the thing status can then be updated again later by code run in a separate thread. |
The initialize methods do return quickly. And they ultimately do set the thing status, but in a separate thread to allow the initialize method to return quickly. Is there an obligation to already set the thing status in the same thread the initialize method was called from? If that’s the case, I misinterpreted and I will have to do many more changes. I thought returning quickly just had to do with not keeping a thread occupied that would initialize other things in other bindings. |
@lolodomo Setting the ting status to unknown was introduced in the binding 7 months ago. It wasn’t there before. The binding pre-dates the creation of the archetype. I read the reasoning for setting thing status unknown (unit tests), but I don’t agree it is right to set it in this case. Introducing it introduced a bug in the binding, which I try to revert here. |
This is at least the clear recommendation for binding developers, here is the code from the binding template:
The comment in the template looks to me really clear ;)
|
@lolodomo Then the developer documentation should be changed: https://www.openhab.org/docs/developer/bindings/ |
Why do you say it is the only reason ? I don't think so. As reviewer, I think my main role is to focus on the good practices and guidelines are followed. So I will not approve this PR myself. Now, this is only my feedback and of course another reviewer can approve and merge this PR. @jlaur was already involved in the review. |
There is no particular difficulty when the bridge/thing initialization is well implemented. This case is very common and properly handled in many bindings. In your thing handler, you just have to first check the status of the bridge. If not yet ONLINE, you set your thing status to OFFLINE/BRIDGE_OFFLINE. |
Yes, of course, but in this case, you set your thing status to OFFLINE/BRIDGE_OFFLINE. |
@lolodomo I don't want to argue this any further. I developed this binding something like 5 years ago, based on the documentation at that point in time (which still is the same in the documentation). It had always worked well and reliably. On Oct. 9th 2021, in another PR #11319, you asked me to put the thing status UNKNOWN lines in. From that point onwards, the binding stopped starting reliably. I now for the first time see the archetype, which was only created after my binding got created, reviewed and accepted, and I don't agree with that specific line in it. |
Wait for @jlaur feedback, he is maybe ok with your changes and will then merge your PR. |
I will be away today, but will be back in the evening. If there will still be any doubts then, I will catch up and try to provide some feedback. |
For reference, here is the original discussion on why the requirement was introduced in the archetype: PR #6160 |
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I did not yet check the final PR but I assume the PR title has to be updated (it will appear in the changelog for the user) ? |
openhab#12819) * Do not set thing status before end of initialization * Change ThingStatusDetail when no communication object * Change bridge config error messages * Bridge status changed handling * Check bridge status in handler init Signed-off-by: Mark Herwege <[email protected]>
openhab#12819) * Do not set thing status before end of initialization * Change ThingStatusDetail when no communication object * Change bridge config error messages * Bridge status changed handling * Check bridge status in handler init Signed-off-by: Mark Herwege <[email protected]>
openhab#12819) * Do not set thing status before end of initialization * Change ThingStatusDetail when no communication object * Change bridge config error messages * Bridge status changed handling * Check bridge status in handler init Signed-off-by: Mark Herwege <[email protected]> Signed-off-by: Andras Uhrin <[email protected]>
openhab#12819) * Do not set thing status before end of initialization * Change ThingStatusDetail when no communication object * Change bridge config error messages * Bridge status changed handling * Check bridge status in handler init Signed-off-by: Mark Herwege <[email protected]>
openhab#12819) * Do not set thing status before end of initialization * Change ThingStatusDetail when no communication object * Change bridge config error messages * Bridge status changed handling * Check bridge status in handler init Signed-off-by: Mark Herwege <[email protected]>
Signed-off-by: Mark Herwege [email protected]
There is a large PR #11963 with new functionality for the Niko Home Control binding that has been open, waiting for review, for a while.
One of the things that got fixed there is an annoying bug. Things did not get initialized properly as the bridge status was already set before the bridge initialization finished. This small PR isolates this fix. I hope that makes it quicker to at least get this fix merged.